<template>
  <div>
    <!--条件筛选-->
    <TopFilter ref="topFilter" :list="topFilterList" :cols="3" labelWidth="110" @filterChange="changeHandle" @onCollapse="collapseHandle"></TopFilter>
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchApi"
      :params="fetchParams"
      :datakey="'records'"
      :isSelectColumn="false"
      :onColumnsChange="columns => this.columns = columns"
      :isExportExcel2="true"
      :exportFileName="'防盗码获取记录.xlsx'"
    >
    </FilterTable>

    <BaseDialog
      :visible.sync="issearch"
      :title="'经销商查询'"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <ownerSeacher  @close="dealercloseHandler" />
    </BaseDialog>
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import {getListByRetailNo,piliangguanbi,getCustomerService} from '@/api/customerService/secneExamine/secneLssue/index';
import ownerSeacher from '@/pages/partsmanage/claim/approve/ownerSeacher';
import { getSccessRecord } from '@/api/customerService/SecurityCode/getSccessRecord/index';
import {getAllUser} from '@/api/customerRepair/activityVisit/resultEntry/index';

export default {
  name: "getSccessRecord",
  mixins: [dictionary],
  components: {ownerSeacher},
  data() {
    return{
      topFilterList: this.createTopFilterList(),
      columns: this.createTableColumns(),
      fetchApi: getSccessRecord,
      fetchParams: {
        xhrAbort: true
      },
      issearch: false,
      rowSelectData: []
    };
  },
  created() {
    this.getDictData();
  },
  methods: {
    async getDictData() {
      let res= await getAllUser();
      console.info(res)
      this.columns.find(x => x.dataIndex == 'obtainContent').dictItems = this.createDictList('5015')
      this.columns.find(x => x.dataIndex == 'acquisitionMethod').dictItems = this.createDictList('5013')
    },
    createTopFilterList() {
      return[
        {
          type: 'INPUT',
          label: 'VIN',
          fieldName: 'vin'
        },
        {
          type: 'SELECT',
          label: '获取方式',
          fieldName: 'acquisitionMethod',
          itemList: this.createDictList('5013'),
        },
        {
          type: 'RANGE_DATE',
          label: '创建日期',
          fieldName: 'createdAt1|createdAt2',
          valueFormat: 'yyyy-MM-dd',
          placeholder: '请选择'
        },
        {
          type: 'INPUT',
          label: '经销商代码',
          fieldName: 'ownerCode',
          placeholder: '请选择',
          initialValue: '',
          unitRender: () => {
            return (
              <div>
                <el-button icon="el-icon-search" onClick={() => this.seacherFun()}></el-button>
                <el-button slot="append" icon="el-icon-delete" onClick={() => this.clearSelectOwnerCode()}></el-button>
              </div>
            );
          },
          change:p=>{
            if(!p){
              this.dealerCode=''
            }
          }
        }
      ]
    },
    createTableColumns () {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 70,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: 'VIN',
          dataIndex: 'vin',
          sorter: true
        },
        {
          title: '车型',
          dataIndex: 'model',
          sorter: true,
        },
        {
          title: '获取内容',
          dataIndex: 'obtainContent',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.obtainContent, '5015')}</span>;
          }
        },
        {
          title: '申请码',
          dataIndex: 'requestCode',
          sorter: true
        },
        {
          title: '防盗码',
          dataIndex: 'securityCode',
          sorter: true,
        },
        {
          title: '获取方式',
          dataIndex: 'acquisitionMethod',
          sorter: true,
          render: props => {
            return <span>{this.createDictText(props.row.acquisitionMethod, '5013')}</span>;
          }
        },
        {
          title: '获取人',
          dataIndex: 'createUserInfo.userName',
          sorter: true,
        },
        {
          title: '获取人经销商代码',
          dataIndex: 'ownerCode',
          sorter: true,
        },
        {
          title: '获取人经销商名称',
          dataIndex: 'ownerName',
          sorter: true,
        },
        {
          title: '获取时间',
          dataIndex: 'createdAt',
          dateFormat: 'yyyy-MM-dd HH:mm:ss',
          sorter: true,
        }
      ]
    },
    seacherFun(){
        this.issearch = true
    },
    clearSelectOwnerCode(){ // 清除选择经销商代码
      this.topFilterList.find(item => item.fieldName === 'ownerCode').initialValue='';
    },
    dealercloseHandler(val){
      console.info(val)
      if(val){
        console.info('1111111111')
        this.topFilterList.find(x=>x.fieldName=='ownerCode').initialValue=val.dealerCode;
      }
      this.issearch=false;
    },
    openDialog(type){
      this.issearch = true
    },
    //清空选择车型
    clearSelectModel(){
      this.topFilterList.find(item => item.fieldName === 'model').initialValue='';
    },
    changeHandle(val) {
      this.fetchParams = Object.assign({}, val);
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    },
    infoClose(rData) {
      this.visibleDrawer = false;
      console.info(rData)
      if (rData.type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
  }
}
</script>

<style scoped>

</style>
